package jjn.daily;

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * @author Jjn
 * @since 2023/8/2 16:38
 */
public class LeetCode822 {
    public int flipgame(int[] fronts, int[] backs) {
        Set<Integer> forbidden = new HashSet<>();
        for (int i = 0; i < fronts.length; i++) {
            if (fronts[i] == backs[i]) {
                forbidden.add(fronts[i]);
            }
        }
        int num = Integer.MAX_VALUE;
        for (int front : fronts) {
            if (!forbidden.contains(front)) {
                num = Math.min(front, num);
            }
        }
        for (int back : backs) {
            if (!forbidden.contains(back)) {
                num = Math.min(back, num);
            }
        }
        return num == Integer.MAX_VALUE ? 0 : num;
    }
    
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            int count = scanner.nextInt();
            int[] front = new int[count];
            int[] back = new int[count];
            for (int i = 0; i < count; i++) {
                front[i] = scanner.nextInt();
            }
            for (int i = 0; i < count; i++) {
                back[i] = scanner.nextInt();
            }
            int flipgame = new LeetCode822().flipgame(front, back);
            System.out.println(flipgame);
        }
    }
}
